﻿@model DHQGHN.PM2.Models.Online.ThongTinChungModel
<script>
      @functions{
          public string GetAntiForgeryToken()
          {
              string cookieToken, formToken;
              AntiForgery.GetTokens(null, out cookieToken, out formToken);
              return cookieToken + "," + formToken;
          }
      }
    $(document).ready(function () {
        $('#headerCauHoi').text('Thông tin của: ' + $('#row' + '@Model.RESIDENT_ID').attr('house_hold_name'));
        $("#RS").text("@Model.RESIDENT_ID");
        var re = $("#RS").text();
        var valData =$("#KQ").text();
        var a = valData.split(',');
        for (var i = 1; i < a.length; i++) {
            if (re == a[i]) {
                $("#row" + re + " button").addClass("glyphicon glyphicon-ok");

            } else {
                $("#row" + a[i] + " button").removeClass("glyphicon glyphicon-ok");

            }

        }
    });

    function ClickButton(Next) {
        $("#divLoading").show();
        var dataSend = {
            'Next': Next,
            'HOUSEHOLD_ID': $("#HOUSEHOLD_ID").val(),
            'RESIDENT_ID': $("#RESIDENT_ID").val(),
            'RESIDENT_GROUP_ID': $(".RESIDENT_GROUP_ID").val(),
            'RELATION_ID': $("input[name='optradio']:checked").val(),
            'NEXT': Next,

        };
        var jqXHR = $.ajax({
            url: '@Url.Action("ThongTinChung", "Online")',
            dataType: 'html',
            method: 'post',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            data: dataSend,
            success: function myfunctionSuccess(data, textStatus, jqXHR) {
                $('#loadPartial').html(data);
            },
            complete: function (jqXHR, textStatus) {
                $("#divLoading").hide();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Có lỗi xảy ra trong quá trình đăng nhập: ' + errorThrown);
            }

        });
    }
    $.ajax({
        url: '@Url.Action("GetAllByListName")',
        dataType: 'json',
        method: 'GET',
        data: { 'tablename': 'RESIDENT_GROUP' },
        success: function (data, textStatus, jqXHR) {
            $.each(data, function (i, item) {
                $(".RESIDENT_GROUP_ID").append('<option value="' + item.CodeID + '">' +
                     item.Name + '</option>');
            });
            $(".RESIDENT_GROUP_ID").val(@Model.RESIDENT_GROUP_ID);
        },
        complete: function () {
            Check();
        }


    });
    $.ajax({
        url: '@Url.Action("GetAllByListName")',
        dataType: 'json',
        method: 'GET',
        data: { 'tablename': 'RELATION' },
        success: function (data, textStatus, jqXHR) {
            $.each(data, function (i, item) {
                $(".RELATION_ID").append('<input type="radio" name="optradio" value="' + item.CodeID + '">' +
                     item.Name + '</input><br \>');

            });
            $("input[name=optradio][value=" + @Model.RELATION_ID + "]").attr('checked', 'checked');
        },
        complete: function () {
            Check();
        }
    });
    function Check() {
        var RESIDENT_GROUP_ID = $(".RESIDENT_GROUP_ID").val();
        var RELATION_ID1 = $("#RELATION_ID").val();
        var radiobutton = $("input[name='optradio']:checked").val();
        var coun = $("#RESIDENT_GROUP_ID").val();
        if (RELATION_ID1 == "") {
            RELATION_ID1 = undefined;
        }
        if (coun == "") {
            coun = null;
        }
        if (RESIDENT_GROUP_ID == coun && radiobutton == RELATION_ID1) {
            $("#divLoading").hide();
            $("#btnNext").removeAttr("disabled");

        }
        else {
            $("#divLoading").show();
            $("#btnNext").attr("disabled", "disabled");

        }

    };
    $("#btnNext").click(function () {
        ClickButton(1);
    });
    $("#btnBack").click(function () {
        ClickButton(0);
    });
</script>

<div class="noidung-nhaponline" id="divLoadPartial">
    <div class="login-fields2">
        <p style="float: left; padding-right: 5px; vertical-align: top;">
            <img src="../Images/rt_arrow.gif">
        <p>Thông tin về Resident:</p>
    </div>
    <div class="row row-online-table1">
        <div class="col-md-3 ">
            @Html.LabelFor(m => m.RESIDENT_ID, new { @class = "control-lable" })
            @Html.HiddenFor(m => m.HOUSEHOLD_ID)
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(m => m.RESIDENT_ID, new { @class = "form-control" })
        </div>
    </div>
    <div class="row row-online-table1">
        <div class="col-md-3">
            @Html.LabelFor(m => m.RESIDENT_GROUP_ID, new { @class = "control-lable" })
        </div>
        <div class="col-md-9">
            <select class="RESIDENT_GROUP_ID form-control "></select>
        </div>
    </div>
    <div class="row row-online-table1">
        <div class="col-md-3 ">
            @Html.LabelFor(m => m.RELATION_ID, new { @class = "control-lable" })
        </div>
        <div class="col-md-4">
            <div class="radio RELATION_ID" style="margin-top: 0%; margin-left: 5%;">

            </div>
        </div>
    </div>
    <div>
        @Html.HiddenFor(model => model.RELATION_ID)
        @Html.HiddenFor(model => model.RESIDENT_GROUP_ID)
    </div>
    <div>
        <input type="button" class="btn btn-small btn-small_online btn-success buttonClick" id="btnNext" value="Tiếp tục">
    </div>
</div>
